package com.acme.bankapp.domain.bank;

import java.util.Arrays;


public class Client {
	
	private String name;
	private Gender gender;
	private int num;
	private int maxNumAccounts = 1;
	private Account[] accounts;
	private StringBuffer info;
		
	public Client(Account account, double amount, String name, Gender g) {
		accounts = new Account [maxNumAccounts];
		num = 1;
		accounts[0] = account;
		accounts[0].deposit(amount);
		this.name = name;
		gender = g;
		info = new StringBuffer("Client " + g.getGender() + name + " has " + num + " account(s): \n" 
		+ Arrays.toString(accounts));
	}
	
	public Client(Account account, double amount) {
		this(account, amount, null, Gender.MALE);
	}
	
	public Client() {
		this(null, 0, null, Gender.MALE);
	}	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + getClientSalutation().hashCode();		
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof Client)) {
			return false;
		}
		Client other = (Client) obj;

		if (!getClientSalutation().equals(other.getClientSalutation())) {			
			return false;
		}			
		return true;
	}
		
	@Override
	public String toString() {		
		return info.toString();
	}

	public String getClientSalutation() {
		return gender.getGender() + name;
	}
	
	public String getClientName() {
		return name;
	}	
	
	public Account getAccount (int num) {
		if (num > this.num) {
			return null;
		}
		return accounts[num]; 
	}

}
